#!/bin/bash
IP='192.168.1.176'
PORT='9200'
INDEX='test'
# 请求地址
REQ_URL="http://$IP:$PORT"
# 索引库请求地址
INDEX_URL="$REQ_URL/$INDEX"

echo -e "\n======== 删除旧库 ========"
curl -X DELETE $INDEX_URL

echo -e "\n======== 创建新库 ========"
curl -X PUT $INDEX_URL -d '
{
	"aliases": {},
	"mappings": {
		"archive": {
			"properties": {
				"belongId": {
					"type": "string"
				},
				"content": {
					"type": "string",
					"store": true,
					"analyzer": "ik_max_word"
				},
				"id": {
					"type": "string",
					"index": "not_analyzed"
				},
				"path": {
					"type": "string",
					"store": true,
					"analyzer": "ik_max_word"
				},
				"title": {
					"type": "string",
					"store": true,
					"analyzer": "ik_max_word"
				},
				"type": {
					"type": "string",
					"index": "not_analyzed",
					"store": true
				}
			}
		}
	},
	"settings": {
		"index": {
			"refresh_interval": "-1",
			"number_of_shards": "1",
			"creation_date": "1604479906989",
			"store": {
				"type": "fs"
			},
			"number_of_replicas": "0",
			"uuid": "U_W8QqdFShCsH4CiHYAF7Q",
			"version": {
				"created": "2040699"
			}
		}
	},
	"warmers": {}
}'
echo -e "\n======== 库结构 ========"
curl -X GET $INDEX_URL?pretty
echo -e "======== 索引库列表 ========"
curl $REQ_URL/_cat/indices